using System.Collections;
using System.Collections.Generic;
using GameFramework.Localization;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace LS.Setting
{
    public partial class ApplicationSetting
    {
        public class GameplaySetting : SettingBase
        {

            private ModifiableValue<float> m_MouseSpeed;
            private ModifiableValue<float> m_CameraAltitude;
            private ModifiableValue<Language> m_Language;

            /// <summary>
            /// 游戏语言
            /// </summary>
            public Language Language
            {
                get
                {
                    return m_Language;
                }
                set
                {
                    m_Language.SetValue(value);
                }
            }

            /// <summary>
            /// 鼠标速度
            /// </summary>
            public float MouseSpeed
            {
                get
                {
                    return m_MouseSpeed;
                }
                set
                {
                    m_MouseSpeed.SetValue(value);
                }
            }

            /// <summary>
            /// 相机高度
            /// </summary>
            public float CameraAltitude
            {
                get
                {
                    return m_CameraAltitude;
                }
                set
                {
                    m_CameraAltitude.SetValue(value);
                }
            }
            /// <summary>
            /// 是否有值被修改
            /// </summary>
            public override bool IsValueChanged
            {
                get
                {
                    return
                    m_MouseSpeed.IsValueChanged ||
                    m_CameraAltitude.IsValueChanged ||
                    m_Language.IsValueChanged;
                }
            }

            public GameplaySetting()
            {
                Load();
            }

            public override void Load()
            {
                SettingComponent setting = LSEntry.Setting;
                LocalizationLoaderComponent localizationLoader = LSEntry.LocalizationLoader;

                if (setting != null)
                {
                    m_MouseSpeed = (ModifiableValue<float>)setting.GetFloat("Gameplay.MouseSpeed", 0.5f);
                    m_CameraAltitude = (ModifiableValue<float>)setting.GetFloat("Gameplay.CameraAltitude", 0.5f);
                }

                if (localizationLoader != null)
                {
                    m_Language = (ModifiableValue<Language>)localizationLoader.Language;
                }
            }

            public override void Save()
            {
                SettingComponent setting = LSEntry.Setting;
                LocalizationLoaderComponent localizationLoader = LSEntry.LocalizationLoader;

                if (setting != null)
                {
                    if (m_MouseSpeed.IsValueChanged)
                        setting.SetFloat("Gameplay.MouseSpeed", m_MouseSpeed.GetValueAndClearChangedState());

                    if (m_CameraAltitude.IsValueChanged)
                        setting.SetFloat("Gameplay.CameraAltitude", m_CameraAltitude.GetValueAndClearChangedState());
                }

                if (localizationLoader != null && m_Language.IsValueChanged)
                {
                    localizationLoader.SetupLanguage(m_Language.GetValueAndClearChangedState());
                }
            }
            
            
            public enum MyEnum
            {
                
            }
        }
    }
}
